package com.example.administrator.nurse.present;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.nurse.R;
import com.example.administrator.nurse.base.BaseActivity;
import com.example.administrator.nurse.model.CommonViewHolder;
import com.example.administrator.nurse.model.bean.money_check_bean;
import com.example.administrator.nurse.util.recyclerViewHelper;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.text.SimpleDateFormat;
import java.util.Date;

import jjobes.SlideDateTimeListener;
import jjobes.SlideDateTimePicker;

/**
 *  Created by Administrator on 2016/4/24.
 *
 */

public class MoneyCheckActivity extends BaseActivity {

    private recyclerViewHelper<money_check_bean> recyclerViewHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        configCommonHeader(MoneyCheckActivity.this, "费用查询", 1);
        initView();
    }

    @Override
    protected int setLayotId() {
        return R.layout.money_check_main;
    }

    @Override
    protected void onFailure(int requestCode, Object object, String errorMsg) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object, String response) {

    }

    private void initView(){
        LinearLayout container = (LinearLayout) f(R.id.container);

        recyclerViewHelper= new recyclerViewHelper<money_check_bean>(this, (XRecyclerView) findViewById(R.id.recyclerView))
                .withAdapter(R.layout.money_check_bean)
                .withTestData(new recyclerViewHelper.TestDataInterface() {
                    @Override
                    public money_check_bean addTestData(int i) {
                        money_check_bean bean = new money_check_bean();
                        bean.setAreaNum("0" + i);
                        bean.setBed("0" + i);
                        bean.setName("林冠宏");
                        bean.setAge("91岁");
                        bean.setSex("男");
                        bean.setStartTime("2016-3-23 12:11:23");
                        bean.setEndTime("2016-3-" + i + "12:12:" + i);
                        bean.setCount("20");
                        bean.setLast("15");
                        bean.setDoc("林先生");
                        bean.setRoom("精神二科");
                        bean.setHospital("007" + i);
                        return bean;
                    }
                })
                .withLoadMore(new recyclerViewHelper.loadMoreListener() {
                    @Override
                    public void loadMore() {

                    }
                })
                .withBindView(new recyclerViewHelper.BindViewListener() {
                    @Override
                    public void bindView(CommonViewHolder holder,final int position) {
                        holder.getConvertView().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(MoneyCheckActivity.this,MoneyItemActivty.class);
                                intent.putExtra("data",recyclerViewHelper.list.get(position));
                                startActivity(intent);
                            }
                        });
                        TextView area,bed,name,sex,age,count,last,starttime,endtime;

                        area = holder.getTextView(R.id.area);
                        bed = holder.getTextView(R.id.number);

                        name = holder.getTextView(R.id.name);
                        sex = holder.getTextView(R.id.sex);
                        age = holder.getTextView(R.id.age);
                        count = holder.getTextView(R.id.count);
                        last = holder.getTextView(R.id.last);
                        starttime = holder.getTextView(R.id.startTime);
                        endtime = holder.getTextView(R.id.endTime);

                        area.setText(recyclerViewHelper.list.get(position).getArea());
                        bed.setText(recyclerViewHelper.list.get(position).getBed());
                        name.setText(recyclerViewHelper.list.get(position).getName());
                        sex.setText(recyclerViewHelper.list.get(position).getSex());
                        age.setText(recyclerViewHelper.list.get(position).getAge());
                        count.setText(recyclerViewHelper.list.get(position).getCount());
                        last.setText(recyclerViewHelper.list.get(position).getLast());
                        starttime.setText(recyclerViewHelper.list.get(position).getStartTime());
                        endtime.setText(recyclerViewHelper.list.get(position).getEndTime());
                    }
                })
                .initRecyclerView();

        /** 添加日期条目 item */
        final View dateStart = LayoutInflater.from(this).inflate(R.layout.time_select_item, (ViewGroup) getWindow().getDecorView(),false);
        dateStart.setOnClickListener(timeClick);
        container.addView(dateStart);
        View dateEnd = LayoutInflater.from(this).inflate(R.layout.time_select_item, (ViewGroup) getWindow().getDecorView(),false);
        dateEnd.setOnClickListener(timeClick);
        ((TextView)dateEnd.findViewById(R.id.text)).setText("结束时间");
        container.addView(dateEnd);
        View dateOut = LayoutInflater.from(this).inflate(R.layout.time_select_item, (ViewGroup) getWindow().getDecorView(),false);
        dateOut.setOnClickListener(timeClick);
        ((TextView)dateOut.findViewById(R.id.text)).setText("出院时间");
        container.addView(dateOut);
    }

    /** 日期选择点击 */
    private View.OnClickListener timeClick = new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            new SlideDateTimePicker.Builder(getSupportFragmentManager())
                    .setListener(new SlideDateTimeListener() {
                        @Override
                        public void onDateTimeSet(Date date) {
                            SimpleDateFormat formatter  = new SimpleDateFormat("yyyy年MM月dd日-HH:mm:ss");
                            String time = formatter.format(date);
                            ((TextView)v.findViewById(R.id.time)).setText(time);
                        }
                    })
                    .setInitialDate(new Date())
                    .setIs24HourTime(true)
                    .build()
                    .show();
        }
    };


}
